const express=require('express');
const router=express.Router();
const PageJson=require("../model/PageJson");
const cheerio=require('cheerio');
const axios=require('axios');
const SofteemNewsItem=require('../model/SofteemNewsItem');

const axios_config={
  headers:{
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
  }
};
//获取软帝资讯新闻
router.get("/getSofteemNews", (req,resp)=>{
  // const url="http://m.softeem.com/web2/index.html";
  // axios.default.get(url,axios_config).then(response=>{
  //   if(response.status==200){
  //     let $=cheerio.load(response.data);
  //     let newsList=[];
  //     $(".news-content").each((index,element)=>{
  //         var softeemNewsItem=new SofteemNewsItem();
  //         softeemNewsItem.imgPath=$(element).children(".news-img").children("img").attr("src");
  //         softeemNewsItem.title=$(element).children(".news-details").children(".news-header").text();
  //         softeemNewsItem.content=$(element).children(".news-details").children(".news-det").text();
  //         softeemNewsItem.date=$(element).children(".news-details").children(".news-time").text();
  //         newsList.push(softeemNewsItem);
  //     });
  //     resp.json(new PageJson("success","获取新闻成功",newsList));
  //   }
  //   else{
  //     resp.json(new PageJson("error","获取新闻失败"));
  //   }
  // }).catch(err=>{
  //   resp.json(new PageJson("error","服务器错误"));
  // });

  const url="http://m.softeem.com/web2/interface.php?action=newstop2";
  axios.default.get(url,axios_config).then(response=>{
    if(response.status==200){
      resp.json(new PageJson("success","获取新闻成功",response.data));
    }
    else{
      resp.json(new PageJson("error","获取新闻失败"));
    }
  }).catch(err=>{
    resp.json(new PageJson("error","服务器错误"));
  });
});


module.exports=router;